<?php

namespace Biz\model\brandIndex;

use Doraemon\pockets\datebase\BaseDbModel;

class BrandQuestionCategory extends BaseDbModel
{

    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'hhz_store';

    const _TABLE_NAME = 'brand_question_category';

    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 9;
    const STATUS = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_DELETE => '删除'
    ];


    public static function getCategorys()
    {
        return self::select('*', [
            "category_status" => self::STATUS_NORMAL,
            "ORDER" => [
                "category_sort" => "ASC",
                "addtime" => "DESC"
            ]
        ]);
    }

    //添加
    public static function addData($data)
    {
        self::insert($data);
        return self::id();
    }

    //修改
    public static function editData($data, $where = [])
    {
        if(!$where) {
            return false;
        }
        return self::update($data, $where);
    }


    public static function getById($id)
    {
        return self::get('*', [
            "id" => $id,
            "category_status" => self::STATUS_NORMAL
        ]);
    }

    public static function searchCategorys($keyword = "")
    {
        if(!$keyword) {
            return [];
        }
        return self::select("*", [
            "category_status" => self::STATUS_NORMAL,
            "category_name[~]" => $keyword
        ]);
    }

}

